package mx.com.mindbits.bandpay.dao;

import java.util.List;

import mx.com.mindbits.dao.DaoSession;
import mx.com.mindbits.dao.contacts;
import mx.com.mindbits.dao.contactsDao;
import mx.com.mindbits.dao.contactsDao.Properties;
import android.content.Context;

public class ContactsDAO extends ConnectionFactory{
	private DaoSession daoSession;
	private contactsDao _contactsDao;
	
	public ContactsDAO(Context context){
		super(context);
		daoSession = daoMaster.newSession();
		_contactsDao = daoSession.getContactsDao();
	}
	
	//Return true if was success the insert
	public boolean insertContacts(contacts _contacts){
		try{
			_contactsDao.insert(_contacts);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	//Return true if the update was success
	public boolean updateContacts(contacts _contacts){
		try{
			_contactsDao.update(_contacts);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	//Return true if delete contact was success
	public boolean deleteContacts(contacts _contacts){
		try{
			_contactsDao.delete(_contacts);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	//Return only one contact
	public contacts getContactById(Long id){
		contacts _contact= null;
		try{
			_contact = _contactsDao.load(id);
		}catch(Exception e){
			
		}
		return _contact;
	}
	
	//Return a contacts list
	public List<contacts> getAllContactsByUser(){
		List<contacts> _listaC= null;
		try{
			//_listaC = _contactsDao.loadAll().;
			_listaC = _contactsDao.queryBuilder().where(Properties.Contact_visible.eq(true))
					.orderAsc(Properties.Contact_name).list();
		}catch(Exception e){
			
		}
		return _listaC;
	}
	
	

}
